fix(terraform): skip label validation for unresolved Terraform references#7978
Open
cx-ori-bendet wants to merge 1 commit intomasterfrom
Open
fix(terraform): skip label validation for unresolved Terraform references#7978cx-ori-bendet wants to merge 1 commit intomasterfrom
cx-ori-bendet wants to merge 1 commit intomasterfrom
Conversation
…nces
KICS's HCL converter wraps bare Terraform references (local.*, var.*, etc.)
in \${...} notation since it cannot resolve them at parse time. These wrapped
strings (e.g. \"\${local.resource_name}\") fail the Kubernetes label value
regex because of the \${} characters, causing false positives.
Add two guards before the regex check:
- is_string(): skip non-string values (e.g. nested objects from dotted keys)
- not contains(labels[key], \"\${\"): skip unresolved Terraform references
Also fix a pre-existing typo in result messages: \"metada\" -> \"metadata\".
Add negative test cases for a Terraform local reference and a prefixed label
key (gateway.istio.io/defaults-for-class).
Fixes #7944
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.








Summary
local.*,var.*,data.*, etc.) in${...}notation since it cannot resolve them at parse time"${local.resource_name}") fail the Kubernetes label value regex because$,{,}are not valid K8s label characters, causing false positivesis_string(labels[key])— skips non-string values (e.g. nested objects that appear from HCL keys containing dots or slashes — also fixes bug(terraform): Detecting valid label as invalid #7938)not contains(labels[key], "${")— skips any value containing an unresolved Terraform reference wrapper"metada"→"metadata"local.*reference and a prefixed label key (gateway.istio.io/defaults-for-class)Fixes #7944
Also fixes #7938
Root cause trace
Test plan
app = local.resource_name— should produce no finding"gateway.istio.io/defaults-for-class"— should produce no findingapp = "g**dy.l+bel"— should still produce a findinggo test ./test/... -run TestQueriesto verify all query tests passI submit this contribution under the Apache-2.0 license.
🤖 Generated with Claude Code